'''
Created on May 29, 2010

@author: tinystrimp
'''

import wx

import __main__

class ProjectNewDlg(wx.Dialog):
  def __init__(self, parent):
    wx.Dialog.__init__(self, parent, -1, 'New Project', size=(500, 300), style=wx.DEFAULT_DIALOG_STYLE)
    
    self._projName = ''
    self._useExistedSrc = False
    self._projPath = ''
    self._excludeFiles = ''
    self._excludeFolders = ''
    
    self.__initializeComponents()
    
  def __initializeComponents(self):
    sizer = wx.BoxSizer(wx.VERTICAL)  
    
    # add project name line
    projNameSizer = wx.BoxSizer(wx.HORIZONTAL)
    
    projNameLabel = wx.StaticText(self, -1, 'Project Name')
    projNameSizer.Add(projNameLabel,  0, wx.ALIGN_CENTRE|wx.ALL, 5)
    
    self._projNameBox = wx.TextCtrl(self)
    self.Bind(wx.EVT_TEXT, self.__projNameChanged, self._projNameBox)
    projNameSizer.Add(self._projNameBox,  1, wx.ALIGN_CENTRE|wx.ALL, 5)
    
    sizer.Add(projNameSizer, 0, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5)  
    
    # add use existed source checkbox line    
    useExistedSrcSizer = wx.BoxSizer(wx.HORIZONTAL)
    
    self._useExistedSrcBox = wx.CheckBox(self, -1, 'Use existed sources')
    self.Bind(wx.EVT_CHECKBOX, self.__useExistedSrcBoxChanged, self._useExistedSrcBox)
    useExistedSrcSizer.Add(self._useExistedSrcBox)
    
    sizer.Add(useExistedSrcSizer, 0, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5)
    
    # add project path line  
    projPathSizer = wx.BoxSizer(wx.HORIZONTAL)
    
    projPathLabel = wx.StaticText(self, -1, 'Project Path')
    projPathSizer.Add(projPathLabel,  0, wx.ALIGN_CENTRE|wx.ALL, 5)
    
    self._projPathBox = wx.TextCtrl(self)
    projPathSizer.Add(self._projPathBox,  1, wx.ALIGN_CENTRE|wx.ALL, 5)
    
    selPathBtn = wx.Button(self, 0, "...", size=(26,26))
    self.Bind(wx.EVT_BUTTON, self.__selProjPath, selPathBtn)
    projPathSizer.Add(selPathBtn, 0, wx.ALIGN_CENTRE|wx.ALL, 5)
    
    sizer.Add(projPathSizer, 0, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5) 
    
    # add exclude files line
    excludeFilesLabel = wx.StaticText(self, -1, 'Excludes files: (splits each by \';\')')
    sizer.Add(excludeFilesLabel, 0, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5)
    
    self._excludeFilesBox = wx.TextCtrl(self)
    self.Bind(wx.EVT_TEXT, self.__excludeFilesChanged, self._excludeFilesBox)
    sizer.Add(self._excludeFilesBox, 0, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5)
    
    # add exclude folders line
    excludeFolderLabel = wx.StaticText(self, -1, 'Excludes files: (splits each by \';\')')
    sizer.Add(excludeFolderLabel, 0, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5)
    
    self._excludeFolderBox = wx.TextCtrl(self)
    self.Bind(wx.EVT_TEXT, self.__excludeFoldersChanged, self._excludeFolderBox)
    sizer.Add(self._excludeFolderBox, 0, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5)
    
    # add OK button
    btnSizer = wx.StdDialogButtonSizer()
    
    okBtn = wx.Button(self, wx.ID_OK)
    okBtn.SetDefault()
    btnSizer.AddButton(okBtn)
    
    cancelBtn = wx.Button(self, wx.ID_CANCEL)
    btnSizer.AddButton(cancelBtn)
    btnSizer.Realize()
    
    sizer.Add(btnSizer, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5)
      
    self.SetSizer(sizer)
    
  def getProjectName(self):
    return self._projName
  
  def getProjectPath(self):
    return self._projPath
  
  def getExcludeFiles(self):
    return self._excludeFiles
  
  def getExcludeFolders(self):
    return self._excludeFolders
  
  def useExistedSrc(self):
    return self._useExistedSrc
  
  def __selProjPath(self, event):
    dlg = wx.DirDialog(None, message='Select project folder',
                             defaultPath = __main__.app.globalSettings().getWorkingPath(),
                             style=0, pos=wx.DefaultPosition, size=wx.DefaultSize, name="wxDirCtrl")
    
    if dlg.ShowModal() == wx.ID_OK:
      path = dlg.GetPath()
      self._projPathBox.SetValue(path)
      self._projPath = path
      
  def __projNameChanged(self, event):
    self._projName = self._projNameBox.GetValue()
    
  def __excludeFilesChanged(self, event):
    self._excludeFiles = self._excludeFilesBox.GetValue()
    
  def __excludeFoldersChanged(self, event):
    self._excludeFolders = self._excludeFolderBox.GetValue()
    
  def __useExistedSrcBoxChanged(self, event):
    cb = event.GetEventObject()
    self._useExistedSrc = cb.Get3StateValue()
    
    
        